{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>用户{:lang('list')}</legend>
    </fieldset>
	<blockquote class="layui-elem-quote layer-clear">
    <div class="demoTable layui-row">

        <div class="layui-form layui-form-pane layui-input-4" >
			<div class="layui-form-item">
				<label class="layui-form-label">会员姓名</label>
				<div class="layui-input-inline layui-form">
					<input class="layui-input" name="key" id="key" placeholder="请输入会员姓名">
				</div>
			</div>
        </div>
		<div class="layui-form layui-form-pane layui-input-4 thio2">
			<div class="layui-form-item">
				<label class="layui-form-label">注册时间</label>
				<div style="width:72%" class="layui-input-inline layui-form">
					<input style="width:100%" type="text" class="layui-input" id="test10" placeholder="请选择时间">
				</div>
			</div>
		</div>
		<div class="layui-form layui-form-pane layui-input-4">
			<div class="layui-form-item">
				<label class="layui-form-label">性别</label>
				<div class="layui-input-inline layui-form">
					<select id="statuslist">
						<option value=""></option>
						{volist name="statuslist" id="statuslist"}
						<option value="{$key}">{$statuslist}</option>
						{/volist}
					</select>
				</div>
			</div>		
        </div>
        <div class="layui-form layui-form-pane layui-input-4">
			<div class="layui-form-item">
				<label class="layui-form-label">会员等级</label>
				<div class="layui-input-inline layui-form">
					<select id="level">
						<option value=""></option>
						{volist name="list_category" id="vo"}
						<option value="{$vo.level}">{$vo.title}</option>
						{/volist}
					</select>
				</div>
			</div>		
		</div>
		<div class="demoTable layui-row layui-input-4">
			<button class="layui-btn" style="margin-top: 5px;" id="search" data-type="reload">{:lang('search')}</button>
			<a href="{:url('index')}" style="margin-top: 5px;" class="layui-btn">{:lang('reset')}</a>
		</div>
    </div>

	</blockquote>
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
{include file="common/foot"/}
<script type="text/html" id="avatarUrl">
	<img src="{{d.avatar}}" style="width:40%;height:100%;"/>
</script>
<script type="text/html" id="eqimgUrl">
	<img src="{{d.eqimg}}" style="width:40%;height:100%;"/>
</script>

<script type="text/html" id="open">
	{{# if(d.user_status==0){ }}
        <input type="checkbox" user_id="{{d.user_id}}" name="user_status" value="{{d.user_status}}" lay-skin="switch" lay-text="{:lang('enabled')}|{:lang('disabled')}" lay-filter="open" checked>
    {{# }else{  }}
        <input type="checkbox" user_id="{{d.user_id}}" name="user_status" value="{{d.user_status}}" lay-skin="switch" lay-text="{:lang('enabled')}|{:lang('disabled')}" lay-filter="open" {{ d.user_status == 0 ? 'checked' : '' }}>
    {{# } }}
</script>
<script type="text/html" id="sex">
    {{# if(d.sex == 1){  }}
        男
    {{# }else if(d.sex == 2){   }}
        女
    {{# }else{ }}
        保密
    {{# } }}
</script>
<script type="text/html" id="img">
    <img style="width:80%;height:100%" src="{{d.avatar}}" alt="">
</script>
<script type="text/html" id="action">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">{:lang('edit')}</a>
</script>
<script>
	layui.use('laydate', function(){
		var laydate = layui.laydate;
						
		//日期时间范围
		laydate.render({
			elem: '#test10'
			,type: 'datetime'
			,range: true
		});
	})
     layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form,$ = layui.jquery;
        var tableIn = table.render({
            id: 'ad',
            elem: '#list',
            url: '{:url("index")}',
            method: 'post',
            page:true,
            cols: [[
                {field: 'user_id',align: 'center', title: '{:lang("id")}', width: 80, fixed: true, sort: true},
                {field: 'realname', align: 'center',title: '真实姓名', width: 100},
                {field: 'nickname', align: 'center',title: '昵称', width: 100},
                {field: 'avatar', align: 'center',title: '微信头像', width: 150,toolbar:'#img'},
                {field: 'sex', align: 'center',title: '性别', width: 60,toolbar:'#sex'},
                {field: 'money', align: 'center',title: '余额', width: 100},
                {field: 'phone', align: 'center',title: '手机号', width: 120},
                {field: 'vip_id', align: 'center',title: 'VIP等级', width: 80, sort: true},
                {field: 'vip_number',align: 'center', title: '会员卡号',width: 180}
                ,{field:'user_status',align:'center', title: '状态',width:80,toolbar: '#open'},
                {field: 'idcard', align: 'center',title: '身份证号', width: 150},
                { width: 160, align: 'center', title: '{:lang("action")}', toolbar: '#action',fixed:'right' }
            ]],
            limit:''
        });
        //搜索
        $('#search').on('click', function () {
			var add_time 	= $('#test10').val();
			var gender  = $('#statuslist').val();
			var nickName  = $('#key').val();
            let level =$('#level').val()
			//alert(addtime);
            if ($.trim(add_time) === '' && $.trim(gender) === '' && $.trim(nickName) === '' && level==='' ){
                layer.msg('{:lang("query_condition")}', {icon: 0});
                return;
            }
				tableIn.reload({
					where: {user_addtime:add_time,sex:gender,realname:nickName,level:level}
				});
        });
        form.on('switch(open)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = obj.elem.getAttribute('user_id');
            var is_open = obj.elem.checked===true?0:1;
            $.post('{:url("adminState")}',{'user_status':is_open,'user_id':id},function (res) {
                layer.close(loading);
                if (res.errorCode == 0) {
						layer.msg(res.msg,{time:1000,icon:1});			
                        tableIn.reload();
                    }else{
                        layer.msg(res.msg,{time:1000,icon:2},function(){
							location.href = res.url;
							});
                        return false;
                    }
            })
        });
        table.on('tool(list)', function (obj) {
            //获取当前点击行的数据
            var data = obj.data;
            console.log(data);
            if (obj.event === 'edit') {
                location.href = `/admin/user/edit.html?id=${data.user_id}`
            }
        });
    })
</script>